package com.itheima.design.mode.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 特定的功能增强实现
 */
public class MyInvationHandler implements InvocationHandler {

    private Object target;

    public MyInvationHandler(Object target) {
        super();
        this.target = target;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //前置增强
        doSomethingBefore();
        Object res = method.invoke(target, args);
        //后置增强
        doSomethingAfter();

        return res;
    }

    private void doSomethingAfter() {
        System.out.println("老板，你觉得怎样，欢迎下次再约！");
    }

    private void doSomethingBefore() {
        System.out.println("老板，这个我试过了，很不错，推荐给你！");
    }
}
